// import CryptoJS from "./vendor/crypto-js.min.js"
import CryptoJS from 'crypto-js'

let mAsesKey = "KeyRTYUIOPASDFGH";
let mAesIV = "IvZWSXEDCRFVTGBY";
let AesUtil = {
	 getAesString:function(data, key, iv) {
		//加密 
		var key = CryptoJS.enc.Utf8.parse(key);
		var iv = CryptoJS.enc.Utf8.parse(iv);
		var encrypted = CryptoJS.AES.encrypt(data, key, {
			iv: iv,
			mode: CryptoJS.mode.CBC,
			padding: CryptoJS.pad.Pkcs7
		});
		return encrypted.toString(); //返回的是base64格式的密文 
	},

	 getDAesString:function(encrypted, key, iv) {
		//解密 
		var key = CryptoJS.enc.Utf8.parse(key);
		var iv = CryptoJS.enc.Utf8.parse(iv);
		var decrypted = CryptoJS.AES.decrypt(encrypted, key, {
			iv: iv,
			mode: CryptoJS.mode.CBC,
			padding: CryptoJS.pad.Pkcs7
		});
		return decrypted.toString(CryptoJS.enc.Utf8);
	},

	//加密
	 encryptAES:function(data) {
		var encrypted = this.getAesString(data, mAsesKey, mAesIV);
		//密文 
		var encrypted1 = CryptoJS.enc.Utf8.parse(encrypted);
		return encrypted;
	},

	//解密 
	 decryptAES:function(data) {
		var decryptedStr = this.getDAesString(data, mAsesKey, mAesIV);
		return decryptedStr;
	}
}

export default AesUtil
